home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ian & Stuart's Australian Mac 1993 September
/
September 93.iso
/
Archives
/
Utilities
/
Text
/
EnToutesLettres
/
ETL.DevDoc
/
FrenchCode.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-11-29
|
3KB
|
158 lines
#include <SetUpA4.h>
static char unites[10][8] = { "zéro ","un ","deux ","trois ","quatre ","cinq ","six ","sept ","huit ","neuf " } ;
static char dizaines[10][14] = { "","dix ","vingt ","trente ","quarante ","cinquante ","soixante ","septante ","quatre-vingt","nonante " } ;
static char multiples[4][9] = { "cent","mille","million" ,"milliard"} ;
static char special[10][10] = { "et ","onze ","douze ","treize ","quatorze ","quinze ","seize ","dix-sept ","dix-huit ","dix-neuf "} ;
char *strcpy(char *s1,char *s2) ;
char *strcat(char *s1,char *s2) ;
void reverse(char *s) ;
short strlen(char *s) ;
short french(char *temp,char *tmpresult,short n) ;
pascal void main(char *text,char *result)
{
char thestring[20],temp[4],tmpresult[256];
short i,j,l,res ;
short plurial ;
RememberA0() ;
SetUpA4() ;
text[12] = 0 ; /* max = 999 999 999 999 */
result[0] = '\0' ;
strcpy(thestring,text) ;
if( strlen(thestring) != 0 )
{
while (thestring[0] == '0')
for (i=0;thestring[i]!=0;thestring[i]=thestring[i+1],i++) ;
plurial = 0 ;
if ( (l = strlen(thestring)) )
{
reverse(thestring) ;
if (l < 12)
{
for ( i=l ; i<12 ; i++ )
thestring[i] = '0' ;
thestring[12] = 0 ;
}
for ( i=3 ; i>=0 ; i--)
{
for ( j=3*i ; j<3*(i+1) ; j++)
temp[j-3*i] = thestring[j] ;
temp[3] = 0 ;
tmpresult[0] = 0 ;
res = french(temp,tmpresult,i) ;
if ( (res > 1) || ((res == 1) && (i != 0)) )
plurial = 1 ;
strcat(result,tmpresult) ;
}
}
else
strcpy(result,unites[0]) ;
}
RestoreA4() ;
}
short french(char *temp,char *tmpresult,short n)
{
register int res,x,y,z;
reverse(temp);
x = temp[0]-'0' ;
y = temp[1]-'0' ;
z = temp[2]-'0' ;
res = ((x*10)+y)*10+z;
if(res!=0)
{
if(x)
{
if(x>1)
strcpy(tmpresult,unites[x]);
strcat(tmpresult,multiples[0]);
if(x>1)
if((n==0)&&(y==0)&&(z==0))
strcat(tmpresult,"s");
strcat(tmpresult," ");
}
if(y>1)
{
strcat(tmpresult,dizaines[y]);
if(y==8)
if((z==0)&&(n==0))
strcat(tmpresult,"s ");
else
strcat(tmpresult," ");
}
if(z)
if(y==1)
strcat(tmpresult,special[z]);
else
{
if((z==1)&&(y!=0)&&(y!=8))
strcat(tmpresult,special[0]);
if((z!=1)||(n!=1)||(x!=0)||(y!=0))
strcat(tmpresult,unites[z]);
}
else
if(y==1)
strcat(tmpresult,dizaines[1]);
if (res && n)
strcat(tmpresult,multiples[n]);
if ((res>1) &&(n>1))
strcat(tmpresult,"s");
if (res &&(n>0))
strcat(tmpresult," ");
}
}
char * strcpy(char *s1,char *s2)
{
asm {
movea.l s1,a0 ; A0 = s1
movea.l s2,a1 ; A1 = s2
move.l a0,d0 ; D0.L = result
@1 move.b (a1)+,(a0)+
bne.s @1
}
}
char *strcat(char *s1,char *s2)
{
asm {
movea.l s1,a0 ; A0 = s1
movea.l s2,a1 ; A1 = s2
move.l a0,d0 ; D0.L = result
@1 tst.b (a0)+
bne.s @1
subq.l #1,a0
@2 move.b (a1)+,(a0)+
bne.s @2
}
}
short strlen(char *s)
{
asm {
moveq #-1,d0 ; D0.L = result
movea.l s,a0 ; A0 = s
@1 addq.l #1,d0
tst.b (a0)+
bne.s @1
}
}
void reverse(char *s)
{
register short i,j ;
register char c ;
for(i=0,j=strlen(s)-1;i<j;i++,j--)
{
c = s[j] ;
s[j] = s[i] ;
s[i] = c ;
}
}